package cn.quevo.cube.api.define;

import cn.quevo.common.annotation.RequiresPermissions;
import cn.quevo.common.entity.ResultEntity;
import cn.quevo.common.enums.ResultStatusEnum;
import cn.quevo.common.lang.StringUtils;
import cn.quevo.core.spring.SpringController;
import cn.quevo.cube.provide.define.entity.CubeBaseColumn;
import cn.quevo.cube.provide.define.entity.query.CubeBaseColumnQuery;
import cn.quevo.cube.provide.define.service.CubeBaseColumnService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 模型字段 RestController
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/12/11 14:51:05
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@RestController("cubeBaseColumnController")
@RequestMapping("/cube/")
public class CubeBaseColumnRestController extends SpringController{

    @Resource(name="cubeBaseColumnService")
    private CubeBaseColumnService cubeBaseColumnService;

    /**
     * 分页加载模型字段
     *
     * @param cubeBaseColumnQuery
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:51:05
     */
    @RequestMapping(value="cubeBaseColumn",method= RequestMethod.GET)
    @RequiresPermissions("cube:cubeBaseColumn:list")
    public ResultEntity page(CubeBaseColumnQuery cubeBaseColumnQuery){
        return cubeBaseColumnService.getPage(cubeBaseColumnQuery);
    }

    /**
     * 保存模型字段
     *
     * @param cubeBaseColumn
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:51:05
     */
    @RequestMapping(value="cubeBaseColumn",method=RequestMethod.POST)
    @RequiresPermissions("cube:cubeBaseColumn:create")
    public ResultEntity create(CubeBaseColumn cubeBaseColumn){
        if(cubeBaseColumnService.create(cubeBaseColumn) <= 0){
            return new ResultEntity(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }

    /**
     * 修改模型字段
     *
     * @param cubeBaseColumn
     * @param id
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:51:05
     */
    @RequestMapping(value="cubeBaseColumn//{id:\\d+}",method=RequestMethod.PUT)
    @RequiresPermissions("cube:cubeBaseColumn:update")
    public ResultEntity update(CubeBaseColumn cubeBaseColumn, @PathVariable("id") Long id){
        if (StringUtils.isBlank(id)) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_UNSELECTED);
        }
        cubeBaseColumn.setId(id);
        if (StringUtils.isBlank(this.cubeBaseColumnService.update(cubeBaseColumn))) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }
}
